package com.hzhr.iot.device.dao;

import com.hzhr.iot.device.dao.mapper.custom.ImplRecordEntityCustomMapper;
import com.hzhr.iot.device.dao.mapper.generator.ImplRecordEntityMapper;
import com.hzhr.iot.device.entity.ImplRecordEntity;
import com.hzhr.iot.device.entity.ext.ImplRecordEntityExt;
import com.hzhr.iot.device.queryModel.custom.ImplRecordCustomQueryModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;

@Repository
public class ImplRecordDao {
    @Autowired
    ImplRecordEntityMapper implRecordEntityMapper;
    @Autowired
    ImplRecordEntityCustomMapper implRecordEntityCustomMapper;

    public int insert(ImplRecordEntity record) {
        if (record == null) return 0;
        int changeCount = implRecordEntityMapper.insert(record);
        return changeCount;
    }

    public int delete(ImplRecordCustomQueryModel queryModel) {
        if (queryModel == null) return 0;
        int changeCount = implRecordEntityCustomMapper.delete(queryModel);
        return changeCount;
    }

    public int update(ImplRecordEntity record) {
        if (record == null) return 0;
        int changeCount = implRecordEntityMapper.updateByPrimaryKey(record);
        return changeCount;
    }

    public int updateProps(ImplRecordCustomQueryModel queryModel) {
        if (queryModel == null) return 0;
        int changeCount = implRecordEntityCustomMapper.updateProps(queryModel);
        return changeCount;
    }

    public ImplRecordEntity selectEntity(ImplRecordCustomQueryModel queryModel) {
        if (queryModel == null) return null;
        List<ImplRecordEntityExt> extList = implRecordEntityCustomMapper.selectExt(queryModel);
        if (extList == null || extList.size() == 0) return null;
        return extList.get(0);
    }
    public List<ImplRecordEntity> selectEntityList(ImplRecordCustomQueryModel queryModel) {
        if (queryModel == null) return null;
        List<ImplRecordEntityExt> extList = implRecordEntityCustomMapper.selectExt(queryModel);
        if (extList == null) return null;
        List<ImplRecordEntity> entityList = new ArrayList<>();
        for (ImplRecordEntityExt ext : extList) {
            entityList.add(ext);
        }
        return entityList;
    }
    public ImplRecordEntityExt selectExt(ImplRecordCustomQueryModel queryModel) {
        if (queryModel == null) return null;
        List<ImplRecordEntityExt> extList = implRecordEntityCustomMapper.selectExt(queryModel);
        if (extList == null || extList.size() == 0) return null;
        return extList.get(0);
    }
    public List<ImplRecordEntityExt> selectExtList(ImplRecordCustomQueryModel queryModel) {
        if (queryModel == null) return null;
        List<ImplRecordEntityExt> extList = implRecordEntityCustomMapper.selectExt(queryModel);
        return extList;
    }

    public int selectCount(ImplRecordCustomQueryModel queryModel) {
        if (queryModel == null) return 0;
        int count = implRecordEntityCustomMapper.selectCount(queryModel);
        return count;
    }
}
